
#ifndef Velyn_Mouse_h
#define Velyn_Mouse_h

#include "OpenGL.h"

// TODO: mouse controler that spins an object according to the input
// of the mouse??

namespace Velyn {
    
    namespace IO {
            
        class Mouse {

        private:
            
            bool leftButton, middleButton, rightButton;
            bool firstTimePressed;
            
            int x, y;
            int originalX, originalY;
            int rotationX, rotationY;
            int previousX, previousY;
            
        public:
            
            void rotateObject() {
                glRotatef(previousY + rotationY, 1.0f, 0.0f, 0.0f);
                glRotatef(previousX + rotationX, 0.0f, 1.0f, 0.0f);
            }
            
            inline int getRotationX() {
                return previousY + rotationY;
            }
            
            inline int getRotationY() {
                return previousX + rotationX;
            }
            
            void pressEvent(int button, int state, int x, int y) {
                leftButton = (button == GLUT_LEFT_BUTTON and state == GLUT_DOWN);
                middleButton = (button == GLUT_MIDDLE_BUTTON and state == GLUT_DOWN);
                rightButton = (button == GLUT_RIGHT_BUTTON and state == GLUT_DOWN);
            }
            
            void motionEvent(int x, int y) {
                if(leftButton) {
                    if(firstTimePressed) {
                        originalX = x;
                        originalY = y;
                    } else {
                        rotationX = x - originalX;
                        rotationY = y - originalY;
                    }
                } else {
                    firstTimePressed = true;
                    previousX += rotationX;
                    previousY += rotationY;
                    rotationX = 0;
                    rotationX = 0;
                }
            }        
        };
   }
}
    
#endif
